﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class ImageSlideForm : ItemFormTemplate
    {
        public ImageSlideForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\ImageSlideForm\\ImageSlideForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();

            if (this.ViewStatus > ItemFormTemplateStatus.Create && this.ViewStatus < ItemFormTemplateStatus.Closed)
            {
                this.demo_control.Play();
            }
        }

        public override void HideView()
        {
            base.HideView();

            this.demo_control.Stop();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.AutoSuspend = false;
            this.demo_control.Orientation = ImageSlideOrientation.RightToLeft;
            this.demo_control.TitleBar.Visible = false;
            this.demo_control.NavigationBar.Visible = ImageSlideNavigationBarVisibility.Auto;
            this.demo_control.LegendsBar.Visible = true;
            this.demo_control.Items.Add(new ImageSlideItem() { Image = global::HML.Demo.Properties.Resources.Control_ImageSlide_Image_1, Text = "唧唧复唧唧，木兰当户织。" });
            this.demo_control.Items.Add(new ImageSlideItem() { Image = global::HML.Demo.Properties.Resources.Control_ImageSlide_Image_2, Text = "不闻机杼声，唯闻女叹息。" });
            this.demo_control.Items.Add(new ImageSlideItem() { Image = global::HML.Demo.Properties.Resources.Control_ImageSlide_Image_3, Text = "问女何所思，问女何所忆。" });
            this.demo_control.Items.Add(new ImageSlideItem() { Image = global::HML.Demo.Properties.Resources.Control_ImageSlide_Image_4, Text = "女亦无所思，女亦无所忆。" });
            this.demo_control.Items.Add(new ImageSlideItem() { Image = global::HML.Demo.Properties.Resources.Control_ImageSlide_Image_5, Text = "昨夜见军帖，可汗大点兵，" });
            this.demo_control.Items.Add(new ImageSlideItem() { Image = global::HML.Demo.Properties.Resources.Control_ImageSlide_Image_6, Text = "军书十二卷，卷卷有爷名。" });
            this.demo_control.Items.Add(new ImageSlideItem() { Image = global::HML.Demo.Properties.Resources.Control_ImageSlide_Image_7, Text = "阿爷无大儿，木兰无长兄，" });
            this.demo_control.Items.Add(new ImageSlideItem() { Image = global::HML.Demo.Properties.Resources.Control_ImageSlide_Image_8, Text = "愿为市鞍马，从此替爷征。" });

            this.autoSuspend_toggleSwitch.IsOn = this.demo_control.AutoSuspend;
            this.autoSuspend_toggleSwitch.Toggled += this.AutoSuspend_toggleSwitch_Toggled;

            this.orientation_dropDownListPlus.Multiple = false;
            this.orientation_dropDownListPlus.BindEnumList<ImageSlideOrientation>(this.demo_control.Orientation);
            this.orientation_dropDownListPlus.SelectedItemsChanged += this.Orientation_dropDownListPlus_SelectedItemsChanged;

            this.titleBarVisible_toggleSwitch.IsOn = this.demo_control.TitleBar.Visible;
            this.titleBarVisible_toggleSwitch.Toggled += this.TitleBarVisible_toggleSwitch_Toggled;

            this.titleBarPadding_label.Text = this.demo_control.TitleBar.TBPadding.ToString();
            this.titleBarPadding_trackBarPlus.Value = this.demo_control.TitleBar.TBPadding.Top;
            this.titleBarPadding_trackBarPlus.ValueChanged += this.TitleBarPadding_trackBarPlus_ValueChanged;

            this.navigationBarVisibledrop_downListPlus.Multiple = false;
            this.navigationBarVisibledrop_downListPlus.BindEnumList<ImageSlideNavigationBarVisibility>(this.demo_control.NavigationBar.Visible);
            this.navigationBarVisibledrop_downListPlus.SelectedItemsChanged += this.NavigationBarVisible_dropDownListPlus_SelectedItemsChanged;

            this.legendsBarVisible_toggleSwitch.IsOn = this.demo_control.LegendsBar.Visible;
            this.legendsBarVisible_toggleSwitch.Toggled += this.LegendsBarVisible_toggleSwitch_Toggled;

        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void AutoSuspend_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.AutoSuspend = control.IsOn;
        }

        private void Orientation_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.Orientation = (ImageSlideOrientation)control.SelectedItem.Tag;
        }

        private void TitleBarVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.TitleBar.Visible = control.IsOn;
        }

        private void TitleBarPadding_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.TitleBar.TBPadding = new TBPadding((int)control.Value, (int)control.Value);
            this.titleBarPadding_label.Text = this.demo_control.TitleBar.TBPadding.Top.ToString();
        }

        private void NavigationBarVisible_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.NavigationBar.Visible = (ImageSlideNavigationBarVisibility)control.SelectedItem.Tag;
        }

        private void LegendsBarVisible_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.LegendsBar.Visible = control.IsOn;
        }

        #endregion

    }
}
